package net.huashitong.threeSeven.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.BaseFilter;
import net.huashitong.threeSeven.entity.IndexData;
import net.huashitong.threeSeven.entity.IndexWithArea;
import net.huashitong.threeSeven.filter.RequestModelFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class IndexWithAreaDao extends StringDao<IndexWithArea> {

    /**
     * 根据时间、指标编码
     * @param filter
     * @return
     */
    public List<IndexWithArea> getIndexInArea(RequestModelFilter filter){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.deadline = :deadline").setParam("deadline", filter.getDeadline());
        query.append(" and obj.indexCode = :indexCode").setParam("indexCode", filter.getIndexCode());
        query.setOrder("areaCode",BaseFilter.DESC);
        return query.listResult(filter);
    }

    //获取最新截止时间
    public String getNewDeadline(){
        GenericQuery query = createQuery("obj");
        query.setOrder("deadline",BaseFilter.DESC);
        IndexWithArea indexWithArea = query.firstResult();
        return indexWithArea.getDeadline();
    }
}
